package com.gis.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gis.bean.Lost;
import com.gis.dao.LostDao;
import com.gis.util.Constant;
import com.gis.util.ResponseUtil;
import com.gis.util.RestResponse;

import cn.hutool.core.util.StrUtil;

/**
 * Servlet implementation class LostUpdateServlet
 */
@WebServlet("/lost/update.do")
public class LostUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LostUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		Integer goodsType = Integer.parseInt(request.getParameter("goodsType"));
		String lostTime = request.getParameter("lossTime");
		Double lng = Double.parseDouble(request.getParameter("lng"));
		Double lat = Double.parseDouble(request.getParameter("lat"));
		String address = request.getParameter("address");
		String description = request.getParameter("description");
		String fileName = request.getParameter("fileName");

		Lost lost = new Lost();
		lost.setId(Integer.parseInt(id));
		lost.setGoodsTypeId(goodsType);
		lost.setLostTime(lostTime);
		lost.setLng(lng);
		lost.setLat(lat);
		lost.setAddress(address);
		lost.setDescription(description);
		if (StrUtil.isNotEmpty(fileName)) {			
			lost.setFileName(fileName);
		}
		int i = LostDao.getInstance().updateLost(lost);
		if (i > 0) {
			ResponseUtil.writeJson(response, RestResponse.success(Constant.UPDATE_SUCCESS));
		} else {
			ResponseUtil.writeJson(response, RestResponse.fail(Constant.UPDATE_FAILED));
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
